package ControlLayer;
import java.util.ArrayList;
import ModelLayer.*;
//model layer package has to be imported

/**
 * Controller class for the address book
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */
public class AddressCtr
{
    
    //declare instance variables to reference containers
   private AddressBook addressBook;
    
   
    public AddressCtr(/*---*/)
    {
        addressBook = AddressBook.getInstance();
    }
    
    /**
     * Accessor to person - getting a Person object from the addressBook
     * @param id: int
     * @return Person - object from the HashMap (addressBook)
     */
    public Person getPerson(int id)
    {
        //this method is to search the container for a person
        //with an id-number equal to the parameter id
        //when person is found, the method is to call print-methods in the TUI layer
        return addressBook.getPerson(id);
    }
    
    /**
     * creator method for Person object - and adding it to the HashMap (addressBook)
     * @param name: String
     * @param address: String
     * @param zipCode: String
     * @param phone: String
     * @return p: Person - added to the HashMap (addressBook)
     */
    public Person createPerson(String name, String address, String zipCode, String phone)
    {
        Person p = new Person(0,name,address,zipCode,phone);
        return addressBook.addPerson(p);
    }
    
    /**
     * Method to removing a Person object from the HashMap (addressBook)
     * @param id: int
     */
    public void removePerson(int id)
    {
        //search for the person and delete the object from the container
        addressBook.removePerson(id);
    }
    
    /**
     * mutator for Person object (p)
     * @param p: Person
     */
    public void setPerson(Person p)
    {
        addressBook.setPerson(p);
    }
    
    /**
     * Method to listing all Person objects in our HashMap (addressBook)
     * @return addressBook: HashMap
     */
    public ArrayList<Person> listAllPersons()
    {
          return addressBook.listAllPersons();
    }
}
